Ext.define('App.reportconfiguration.view.field.ReportConfigurationKpiGridField', {
    extend: 'Extend.form.field.GridField',
    alias: ['widget.ReportConfigurationKpiGridField'],
    border: false,
    submitFields: ['id', 'automaticCalculation', 'hidden', 'kpiConfiguration.id', {
        column: 'index',
        field: 'idx'
    }],
    roweditable: true,
    sortableColumns: false,
    userCls: 'high-line28',
    columns: [{
        text: 'ID',
        dataIndex: 'id',
        hidden: true,
        sortable: false
    }, {
        text: '名称',
        dataIndex: 'kpiname',
        flex: 3
    }, {
        text: '自动计算',
        dataIndex: 'automaticCalculation',
        editor: {xtype: 'booleancombobox'},
        flex: 1,
        renderer: function (v, m, r) {
            if (v === true) {
                return "是";
            } else {
                return "否";
            }
        }
    }, {
        text: '隐藏',
        dataIndex: 'hidden',
        editor: {xtype: 'booleancombobox'},
        flex: 1,
        renderer: function (v, m, r) {
            if (v === true) {
                return "是";
            } else {
                return "否";
            }
        }
    }],
    addHandler: function () {
        var grid = this;
        var store = this.getStore();
        var notins = [];
        store.each(function (record) {
            notins.push(record.get('kpiConfiguration').id);
        })
        Ext.create('Extend.window.SelectionWindow', {
            height: 500,
            grid: 'App.kpiconfiguration.view.KpiConfigurationSelection',
            extraParams: {'params.id_notin': notins},
            listeners: {
                selected: function (rs) {
                    if (rs.length > 0) {
                        var rcks = [];
                        for (var i = 0; i < rs.length; i++) {
                            var kc = rs[i];
                            var rck = Ext.create('App.reportconfiguration.model.ReportConfigurationKpiModel', {kpiConfiguration: kc.data})
                            if (kc.get('expression') && kc.get('tableFields')) {
                                rck.set('automaticCalculation', true);
                            }
                            rck.new = true;
                            rcks.push(rck);
                            // var rowedit = grid.findPlugin('extendrowediting');
                            // rowedit.startEdit(rck, 2)
                        }
                        grid.loadRecords(rcks, true);
                    }
                }
            }
        }).show();
    }
})